
$(function(){
    $("#captchaCodeImg").click(function(){
        $("#captchaCodeImg").attr("src",WEB_ROOT+"/captcha/CapthcaImage?"+(new Date()).getTime());
    });

    $('#id-submit').click(function(){
        var username = $("#usernamediv").val();
        var password = $.md5($.md5($("#passworddiv").val()));
        var capcode = $("#checkcodediv").val();
        $.ajax({
            url : WEB_ROOT+'/login/check',
            data : {"username":username,"password":password,"capcode":capcode},
            datatype:'json',
            success : function(obj) {
                if(obj.flag == "success"){
                    window.location.href = WEB_ROOT + '/main/pageInit';
                }else{
                    $("#msgid").html("<b>X</b>"+obj.msg);
                }
            },
            error:function(){
                $("#captchaCodeImg").attr("src",WEB_ROOT+"captcha/CapthcaImage?"+(new Date()).getTime());
            }
        });
    });

    $('#checkcodediv').keydown(function(e){
        if(e.keyCode==13){
            $('#id-submit').click();
        }
    });
    $('#usernamediv').focus();
});